#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
int main(){
  int fd[2];
  int ret = pipe(fd);
  if(ret < 0){
    perror("pipe");
    return 0;
  }
  pid_t pid = fork();
  if(pid < 0){
    perror("fork");
    return 0;
  }
  else if(pid==0){
    close(fd[1]);
    printf("child fd[0] : %d\n",fd[0]);
    printf("child fd[1] : %d\n",fd[1]);
    char buf1[1024];
    read(fd[0],buf1,sizeof(buf1)-1);
    printf("child say:%s",buf1);
    exit(1);
  }
  else{
    close(fd[0]);
    printf("father fd[0] : %d\n",fd[0]);
    printf("father fd[1] : %d\n",fd[1]); 
    char buf[] = "i am father";
    write(fd[1],buf,strlen(buf));
  }
  while(1){
    sleep(1);
  }
  return 0;
}
